package com.wxp.demo08.list;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.wxp.demo08.R;
import com.wxp.demo08.list.adapter.PlanetListWithButtonAdapter;
import com.wxp.demo08.list.model.PlanetModel;
import com.wxp.demo08.util.ToastUtil;

import java.util.List;

/**
 * 2.2.2 列表视图ListView-带按钮
 */
public class ListFocusActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private List<PlanetModel> planetList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_list_focus);

        this.setTitle("2.2.2 列表视图ListView-带按钮");

        ListView lv_planet = findViewById(R.id.lv_planet);
        planetList = PlanetModel.getDefaultList();
        PlanetListWithButtonAdapter adapter = new PlanetListWithButtonAdapter(this, planetList);
        lv_planet.setAdapter(adapter);
        lv_planet.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ToastUtil.show(this, "条目被点击了，" + planetList.get(position).name);
    }
}